﻿using System;

namespace LxCFD
{
    public struct PhysicalFaceOrthCorrect : IPhysicalFace
    {
        public Vector3d Normal;//lenth为面的面积
        public double gDiff;
        public double gT;
        public void SetFace(ref FvFace face, ref Vector3d Df)
        {
            Normal = Vector3d.XXYYZZProduct(face.Normal, Df);
            gDiff = Normal.CalLength() / face.OToNLength;
            gT = Vector3d.DotProduct(Normal, face.OToN) / Math.Pow(face.OToNLength, 2);
        }
        private double calNonOrthogonalityCorrection(ref FvFace face, Vector3d aveGrad, double[] phi)
        {
            return Vector3d.DotProduct(aveGrad, Normal - gT * face.OToN) + (phi[face.NSideCell] - phi[face.OSideCell]) * (gT - gDiff);
        }
        public double CalNonOrthogonalityCorrection_inner(ref FvFace face, Vector3d[] gradPhi, double[] phi)//公式整合
        {
            return calNonOrthogonalityCorrection(ref face, face.CalAverage(gradPhi), phi);
        }
        public double CalNonOrthogonalityCorrection_bound(ref FvFace face, Vector3d[] gradPhi, double[] phi)
        {
            return calNonOrthogonalityCorrection(ref face, gradPhi[face.OSideCell], phi);
        }
    }
}
